package org.codeart.chainrespon.example03;

import org.codeart.chainrespon.example02.AuthService;
import org.codeart.chainrespon.pojo.AuthInfo;

import java.text.ParseException;
import java.util.Date;

public class Level2AuthLink extends AuthLink {
    
    private final Date startDate = dateFormatter.parse("2024-01-01 00:00:00");
    private final Date endDate = dateFormatter.parse("2024-05-20 00:00:00");

    public Level2AuthLink(String levelUserId, String levelUsername) throws ParseException {
        super(levelUserId, levelUsername);
    }

    @Override
    public AuthInfo doAuth(String uid, String orderId, Date authDate) {
        Date date = AuthService.queryAuthInfo(levelUserId, orderId);
        if (date == null) {
            return new AuthInfo("0001", "单号: " + orderId, "状态: 待二级审核人审批" + levelUsername);
        }
        AuthLink link = super.getNext();
        if (link == null) {
            return new AuthInfo("0001", "单号: " + orderId, "状态: 二级审核完成", "审批人: " + levelUsername);
        }
        if (authDate.before(startDate) && authDate.after(endDate)) {
            return new AuthInfo("0001", "单号: " + orderId, "状态: 二级审核完成", "审批人: " + levelUsername);
        }
        return link.doAuth(uid, orderId, authDate);
    }
}
